var express = require('express');
var router = express.Router();
var db = require('../bin/db');

router.get('/index.html', function (req, res) {
    var authkey = req.query.authkey;
    db.pool.getConnection(function (err, client) {
        var sql = "SELECT id,name,app_open,email_open,weChat_open,tel_open,tel_num,`Language` from users where authkey = '"+authkey+"'";
        client.query(sql, function (err, rows) {
        var Result = rows[0];
        if (Result){
            var name =Result.name;
            var id = Result.id;
            var app_open = Result.app_open;
            var email_open = Result.email_open;
            var weChat_open = Result.weChat_open;
            var tel_open = Result.tel_open;
            var tel_num = Result.tel_num;
            var Language = Result.Language;
            var views;      //模板名字
            var Language_js;  //语言包文件
            if (Language == "zh_FT"){
                Language_js = 'zh_ft.js';
            }else if (Language == "ru"){
                Language_js = 'ru.js'
            }else if (Language == "ko"){
                Language_js = 'ko.js'
            }else if (Language == "en"){
                Language_js = 'en.js'
            }else if (Language == "de"){
                Language_js = 'de.js'
            }else if (Language == "es"){
                Language_js = 'es.js'
            }else if (Language == "it"){
                Language_js = 'it.js'
            }else if (Language == "fr"){
                Language_js = 'fr.js'
            }else if (Language == "ja"){
                Language_js = 'ja.js'
            }else if (Language == "zh"){
                Language_js = 'zh.js'
            }
            if (Language == "zh"){
                views = 'index';
            }else{
                views = 'index_en'
            }
            res.render(views,{
                "State":{
                    "app_ope":app_open,
                    "email_open":email_open,
                    "weChat_open":weChat_open,
                    "tel_open":tel_open,
                    "tel_num":tel_num
                 },
                "Language_js":Language_js});
        }else {
            res.send("授权码失效")
        }
        });

    })
});


module.exports = router;
